#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 3e5 + 10;

int n;
LL f[N][2];
LL a[N];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];

    LL res = 1e18;
    //第一头喂
    f[1][1] = a[1];
    f[1][0] = a[1];
    for(int i = 2; i <= n; i ++){
        f[i][1] = min(f[i - 1][0], f[i - 1][1]) + a[i];
        f[i][0] = f[i - 1][1];
    }

    res = min(f[n][0], f[n][1]);

    //第一头没喂
    if(n == 2){
        res = min(res, a[2]);
    }else{
        f[2][0] = a[2];
        f[2][1] = a[2];

        for(int i = 3; i <= n; i ++){
            f[i][1] = min(f[i - 1][0], f[i - 1][1]) + a[i];
            f[i][0] = f[i - 1][1];
        }

        res = min(res, f[n][1]);
    }

    cout << res << '\n';




    return 0;
}